﻿/**  版本信息模板在安装目录下，可自行修改。
* kecheng.cs
*
* 功 能： N/A
* 类 名： kecheng
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2014/11/30 14:41:48   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace XinKuaiJi.DAL
{
	/// <summary>
	/// 数据访问类:kecheng
	/// </summary>
	public partial class kecheng
	{
		public kecheng()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("k_id", "kecheng"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int k_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from kecheng");
			strSql.Append(" where k_id=@k_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@k_id", MySqlDbType.Int32)
			};
			parameters[0].Value = k_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(XinKuaiJi.Model.kecheng model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into kecheng(");
			strSql.Append("k_name,k_beizhu)");
			strSql.Append(" values (");
			strSql.Append("@k_name,@k_beizhu)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@k_name", MySqlDbType.VarChar,30),
					new MySqlParameter("@k_beizhu", MySqlDbType.VarChar,50)};
			parameters[0].Value = model.k_name;
			parameters[1].Value = model.k_beizhu;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XinKuaiJi.Model.kecheng model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update kecheng set ");
			strSql.Append("k_name=@k_name,");
			strSql.Append("k_beizhu=@k_beizhu");
			strSql.Append(" where k_id=@k_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@k_name", MySqlDbType.VarChar,30),
					new MySqlParameter("@k_beizhu", MySqlDbType.VarChar,50),
					new MySqlParameter("@k_id", MySqlDbType.Int32,11)};
			parameters[0].Value = model.k_name;
			parameters[1].Value = model.k_beizhu;
			parameters[2].Value = model.k_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int k_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from kecheng ");
			strSql.Append(" where k_id=@k_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@k_id", MySqlDbType.Int32)
			};
			parameters[0].Value = k_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string k_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from kecheng ");
			strSql.Append(" where k_id in ("+k_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XinKuaiJi.Model.kecheng GetModel(int k_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select k_id,k_name,k_beizhu from kecheng ");
			strSql.Append(" where k_id=@k_id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@k_id", MySqlDbType.Int32)
			};
			parameters[0].Value = k_id;

			XinKuaiJi.Model.kecheng model=new XinKuaiJi.Model.kecheng();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XinKuaiJi.Model.kecheng DataRowToModel(DataRow row)
		{
			XinKuaiJi.Model.kecheng model=new XinKuaiJi.Model.kecheng();
			if (row != null)
			{
				if(row["k_id"]!=null && row["k_id"].ToString()!="")
				{
					model.k_id=int.Parse(row["k_id"].ToString());
				}
				if(row["k_name"]!=null)
				{
					model.k_name=row["k_name"].ToString();
				}
				if(row["k_beizhu"]!=null)
				{
					model.k_beizhu=row["k_beizhu"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select k_id,k_name,k_beizhu ");
			strSql.Append(" FROM kecheng ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM kecheng ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.k_id desc");
			}
			strSql.Append(")AS Row, T.*  from kecheng T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "kecheng";
			parameters[1].Value = "k_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

